home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsStyleContext.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  9KB  |  222 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   David Hyatt <hyatt@netscape.com>
  24.  *   Pierre Phaneuf <pp@ludusdesign.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  28.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. #ifndef _nsStyleContext_h_
  41. #define _nsStyleContext_h_
  42.  
  43. #include "nsRuleNode.h"
  44. #include "nsIAtom.h"
  45.  
  46. class nsPresContext;
  47.  
  48. /**
  49.  * An nsStyleContext represents the computed style data for an element.
  50.  * The computed style data are stored in a set of structs (see
  51.  * nsStyleStruct.h) that are cached either on the style context or in
  52.  * the rule tree (see nsRuleNode.h for a description of this caching and
  53.  * how the cached structs are shared).
  54.  *
  55.  * Since the data in |nsIStyleRule|s and |nsRuleNode|s are immutable
  56.  * (with a few exceptions, like system color changes), the data in an
  57.  * nsStyleContext are also immutable (with the additional exception of
  58.  * GetUniqueStyleData).  When style data change,
  59.  * nsFrameManager::ReResolveStyleContext creates a new style context.
  60.  *
  61.  * Style contexts are reference counted.  References are generally held
  62.  * by:
  63.  *  1. the |nsIFrame|s that are using the style context and
  64.  *  2. any *child* style contexts (this might be the reverse of
  65.  *     expectation, but it makes sense in this case)
  66.  * Style contexts participate in the mark phase of rule node garbage
  67.  * collection.
  68.  */
  69.  
  70. class nsStyleContext
  71. {
  72. public:
  73.   nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag, 
  74.                  nsRuleNode* aRuleNode, nsPresContext* aPresContext) NS_HIDDEN;
  75.   ~nsStyleContext() NS_HIDDEN;
  76.  
  77.   NS_HIDDEN_(void*) operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW;
  78.   NS_HIDDEN_(void) Destroy();
  79.  
  80.   nsrefcnt AddRef() {
  81.     ++mRefCnt;
  82.     NS_LOG_ADDREF(this, mRefCnt, "nsStyleContext", sizeof(nsStyleContext));
  83.     return mRefCnt;
  84.   }
  85.  
  86.   nsrefcnt Release() {
  87.     --mRefCnt;
  88.     NS_LOG_RELEASE(this, mRefCnt, "nsStyleContext");
  89.     if (mRefCnt == 0) {
  90.       Destroy();
  91.       return 0;
  92.     }
  93.     return mRefCnt;
  94.   }
  95.  
  96.   nsPresContext* PresContext() const { return mRuleNode->GetPresContext(); }
  97.  
  98.   nsStyleContext* GetParent() const { return mParent; }
  99.  
  100.   nsStyleContext* GetFirstChild() const { return mChild; }
  101.  
  102.   nsIAtom* GetPseudoType() const { return mPseudoTag; }
  103.  
  104.   NS_HIDDEN_(already_AddRefed<nsStyleContext>)
  105.   FindChildWithRules(const nsIAtom* aPseudoTag, nsRuleNode* aRules);
  106.  
  107.   NS_HIDDEN_(PRBool)    Equals(const nsStyleContext* aOther) const;
  108.   PRBool    HasTextDecorations() { return mBits & NS_STYLE_HAS_TEXT_DECORATIONS; };
  109.  
  110.   NS_HIDDEN_(void) GetBorderPaddingFor(nsStyleBorderPadding& aBorderPadding);
  111.  
  112.   NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, nsStyleStruct* aStruct);
  113.  
  114.   nsRuleNode* GetRuleNode() { return mRuleNode; }
  115.   void AddStyleBit(const PRUint32& aBit) { mBits |= aBit; }
  116.  
  117.   /*
  118.    * Mark this style context's rule node (and its ancestors) to prevent
  119.    * it from being garbage collected.
  120.    */
  121.   NS_HIDDEN_(void) Mark();
  122.  
  123.   /*
  124.    * Get the style data for a style struct.  This is the most important
  125.    * member function of nsIStyleContext.  It fills in a const pointer
  126.    * to a style data struct that is appropriate for the style context's
  127.    * frame.  This struct may be shared with other contexts (either in
  128.    * the rule tree or the style context tree), so it should not be
  129.    * modified.
  130.    *
  131.    * This function will NOT return null (even when out of memory) when
  132.    * given a valid style struct ID, so the result does not need to be
  133.    * null-checked.
  134.    *
  135.    * The typesafe functions below are preferred to the use of this
  136.    * function.
  137.    *
  138.    * See also |nsIFrame::GetStyleData| and the other global
  139.    * |GetStyleData| in nsIFrame.h.
  140.    */
  141.   NS_HIDDEN_(const nsStyleStruct*) NS_FASTCALL GetStyleData(nsStyleStructID aSID);
  142.  
  143.   /**
  144.    * Define typesafe getter functions for each style struct by
  145.    * preprocessing the list of style structs.  These functions are the
  146.    * preferred way to get style data.  The macro creates functions like:
  147.    *   const nsStyleBorder* GetStyleBorder();
  148.    *   const nsStyleColor* GetStyleColor();
  149.    */
  150.  
  151.   #define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_)                      \
  152.     const nsStyle##name_ * GetStyle##name_() {                                \
  153.       return NS_STATIC_CAST(const nsStyle##name_*,                            \
  154.                             GetStyleData(eStyleStruct_##name_));              \
  155.     }
  156.   #include "nsStyleStructList.h"
  157.   #undef STYLE_STRUCT
  158.  
  159.  
  160.   NS_HIDDEN_(const nsStyleStruct*) PeekStyleData(nsStyleStructID aSID);
  161.  
  162.   NS_HIDDEN_(nsStyleStruct*) GetUniqueStyleData(const nsStyleStructID& aSID);
  163.  
  164.   NS_HIDDEN_(void) ClearStyleData(nsPresContext* aPresContext);
  165.  
  166.   NS_HIDDEN_(nsChangeHint) CalcStyleDifference(nsStyleContext* aOther);
  167.  
  168. #ifdef DEBUG
  169.   NS_HIDDEN_(void) DumpRegressionData(nsPresContext* aPresContext, FILE* out,
  170.                                       PRInt32 aIndent);
  171.  
  172.   NS_HIDDEN_(void) List(FILE* out, PRInt32 aIndent);
  173. #endif
  174.  
  175. protected:
  176.   NS_HIDDEN_(void) AppendChild(nsStyleContext* aChild);
  177.   NS_HIDDEN_(void) RemoveChild(nsStyleContext* aChild);
  178.  
  179.   NS_HIDDEN_(void) ApplyStyleFixups(nsPresContext* aPresContext);
  180.  
  181.   nsStyleContext* mParent;
  182.  
  183.   // children are maintained in two circular doubly-linked lists,
  184.   // mEmptyChild for children whose rule node is the root rule node, and
  185.   // mChild for other children.  The order of children is not
  186.   // meaningful.
  187.   nsStyleContext* mChild;
  188.   nsStyleContext* mEmptyChild;
  189.   nsStyleContext* mPrevSibling;
  190.   nsStyleContext* mNextSibling;
  191.  
  192.   // If this style context is for a pseudo-element, the pseudo-element
  193.   // atom.  Otherwise, null.
  194.   nsCOMPtr<nsIAtom> mPseudoTag;
  195.  
  196.   // The rule node is the node in the lexicographic tree of rule nodes
  197.   // (the "rule tree") that indicates which style rules are used to
  198.   // compute the style data, and in what cascading order.  The least
  199.   // specific rule matched is the one whose rule node is a child of the
  200.   // root of the rule tree, and the most specific rule matched is the
  201.   // |mRule| member of |mRuleNode|.
  202.   nsRuleNode* const       mRuleNode;
  203.  
  204.   // |mCachedStyleData| points to both structs that are owned by this
  205.   // style context and structs that are owned by one of this style
  206.   // context's ancestors (which are indirectly owned since this style
  207.   // context owns a reference to its parent).  If the bit in |mBits| is
  208.   // set for a struct, that means that the pointer for that struct is
  209.   // owned by an ancestor rather than by this style context.
  210.   nsCachedStyleData       mCachedStyleData; // Our cached style data.
  211.   PRUint32                mBits; // Which structs are inherited from the
  212.                                  // parent context.
  213.   PRUint32                mRefCnt;
  214. };
  215.  
  216. NS_HIDDEN_(already_AddRefed<nsStyleContext>)
  217. NS_NewStyleContext(nsStyleContext* aParentContext,
  218.                    nsIAtom* aPseudoTag,
  219.                    nsRuleNode* aRuleNode,
  220.                    nsPresContext* aPresContext);
  221. #endif
  222.